package UI;

import facecat.topin.core.*;
import facecat.topin.btn.*;
import facecat.topin.tab.*;

import java.util.*;
import facecat.topin.div.*;

public class FCDraw {
    public static FCSize drawText(FCPaint paint, String text, long dwPenColor, FCFont font, int x, int y)
    {
        FCSize tSize = paint.textSize(text, font, -1);
        FCRect tRect = new FCRect(x, y, x + tSize.cx, y + tSize.cy);
        paint.drawText(text, dwPenColor, font, tRect, -1);
        return tSize;
    }

    public static int drawUnderLineNum(FCPaint paint, double value, int digit, FCFont font, long fontColor, boolean zeroAsEmpty, int x, int y)
    {
        if (zeroAsEmpty && value == 0)
        {
            String text = "-";
            FCSize size = paint.textSize(text, font, -1);
            FCDraw.drawText(paint, text, fontColor, font, x, y);
            return size.cx;
    }
        else
        {
            String[] nbs = FCTran.getValueByDigit(value, digit).split("[.]");
            if (nbs.length == 1)
            {
                FCSize size = paint.textSize(nbs[0], font, -1);
                FCDraw.drawText(paint, nbs[0], fontColor, font, x, y);
                return size.cx;
            }
            else
            {
                FCSize decimalSize = paint.textSize(nbs[0] + ".", font, -1);
                FCSize size = paint.textSize(nbs[1], font, -1);
                FCDraw.drawText(paint, nbs[0] + ".", fontColor, font, x, y);
                FCDraw.drawText(paint, nbs[1], fontColor, font, x
                    + decimalSize.cx + 1, y);
                return decimalSize.cx + size.cx;
            }
        }
    }

    public static int drawUnderLineNum2(FCPaint paint, double value, int digit, FCFont font, long fontColor, boolean zeroAsEmpty, int x, int y)
    {
        if (zeroAsEmpty && value == 0)
        {
            return 0;
        }
        else
        {
            String[] nbs = FCTran.getValueByDigit(value, digit).split("[.]");
            if (nbs.length == 1)
            {
                FCSize size = paint.textSize(nbs[0], font, -1);
                FCDraw.drawText(paint, nbs[0], fontColor, font, x, y);
                return size.cx;
            }
            else
            {
                FCSize decimalSize = paint.textSize(nbs[0] + ".", font, -1);
                FCSize size = paint.textSize(nbs[1], font, -1);
                FCDraw.drawText(paint, nbs[0] + ".", fontColor, font, x, y);
                FCDraw.drawText(paint, nbs[1], fontColor, font, x
                    + decimalSize.cx + 1, y);
                return decimalSize.cx + size.cx;
            }
        }
    }

    public static long getPriceColor(double price, double comparePrice)
    {
        if (price != 0)
        {
            if (price > comparePrice)
            {
                return FCColor.rgb(255, 82, 82);
            }
            else if (price < comparePrice)
            {
                return FCColor.rgb(46, 255, 50);
            }
        }
        return FCColor.rgb(190, 190, 235);
    }
}
